<?php
namespace app\index\controller;

class News extends BaseHome
{
    public function index()
    {
        $lbp=db("lb")->where("fid=10")->find();
        $this->assign("lbp",$lbp);
        
        $lbm=db("lb")->where("fid=11")->find();
        $this->assign("lbm",$lbm);
        
        $id=\input('id');
        if(empty($id)){
            $re=db("news_type")->order("ty_id asc")->limit(1)->find();
            $id=$re['ty_id'];
        }
        $tui=db("news")->where("status=1 and groom=1 and fid=$id")->order('sort asc')->find();
        $this->assign("tui",$tui);
        $res=db("news_type")->order("ty_id asc")->select();
        $this->assign("res",$res);
        
        $list=db("news")->where("status=1 and groom=1 and fid=$id")->where(['id'=>['neq',$tui['id']]])->order(['sort'=>'asc','id'=>'desc'])->paginate(4);
        $this->assign("list",$list);
        $page=$list->render();
        $this->assign("page",$page);
        
        $type=db("news_type")->where("ty_id=$id")->find();
        $this->assign("type",$type);
        

        
        return \view('index');
    }
    public function detail()
    {
        $lbp=db("lb")->where("fid=10")->find();
        $this->assign("lbp",$lbp);
    
        $lbm=db("lb")->where("fid=11")->find();
        $this->assign("lbm",$lbm);
    
        $id=\input('id');
        $re=db("news")->where("id=$id")->find();
        $this->assign("re",$re);
    
        db("news")->where("id=$id")->setInc("browse",1);
    
        //上一篇
        $pre=db('news')->where("id<$id and status=1")->order("id desc")->limit("1")->find();
        $this->assign("pre",$pre);
    
        //下一篇
        $nre=db('news')->where("id>$id and status=1")->order("id asc")->limit("1")->find();
        $this->assign("nre",$nre);
    
        $res=db("news_type")->order("ty_id asc")->select();
        $this->assign("res",$res);
    
        return \view('detail');
    }
    
    
}